<template>
	<view class="margin text-black radius bg-white" @click="gotoCourseInfo">
		<view class="flex align-center solid-bottom padding-tb-sm">
			<text class="cuIcon-titles text-green"></text>
			<text class="text-xl text-bold">{{course.name}}</text>
		</view>
		<view v-if="course.classTime.length>0" class="padding-sm">
			<view>{{dateFilter(course.classTime).title}}</view>
			<view class="flex align-center justify-between margin-top-sm">
				<view>
					{{parseTime(dateFilter(course.classTime).startTime, '{y}-{m}-{d} {h}:{i}') }}
					——
					{{parseTime(dateFilter(course.classTime).endTime, '{h}:{i}')}}
				</view>
				<view>{{dateFilter(course.classTime).place}}</view>
			</view>
		</view>
		<view v-else class="padding-sm flex align-center justify-between">暂未安排课程</view>
	</view>
</template>

<script>
	import { parseTime } from "@/utils/parse.js"
	
	export default {
		name:"course-list-item",
		props:{
			course: {
				required: true,
				type:Object
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			parseTime,
			// 跳转课程详情页
			gotoCourseInfo() {
				this.$store.commit("course/set_courseId", this.course.id)
				uni.navigateTo({
					url: "/pages/course/course-info/course-info"
				})
			},
			dateFilter(list) {
				const today = new Date().getTime()
				let i = 0
				for(;i<list.length;i++){
					if (Number.parseInt(list[i].startTime+"000")>=today) {
						break
					}
				}
				if(i===list.length){
					return list[list.length-1];
				} else {
					return list[i];
				}
				
			}
		}
	}
</script>

<style>

</style>
